package com.op.teachingliteapp.util;

import android.graphics.Bitmap;
import android.graphics.Matrix;

import android.view.View;


import java.io.ByteArrayOutputStream;

/**
 * Created by Genji on 2015/4/11.
 */
public class ScreenCapUtil {
   





    public static Bitmap screenCapToBitmap(View view) {
        view.destroyDrawingCache();
        view.setDrawingCacheEnabled(true);

        return view.getDrawingCache();


    }

    public static byte[] screenCapToByte( View view) {
        byte[] bytes;
        Bitmap bitmap = screenCapToBitmap(view);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.WEBP, 50, baos);
        bytes = baos.toByteArray();

        return bytes;


    }
    private static Bitmap decode(Bitmap bitmap, int newWidth ,int newHeight) {
        int width = bitmap.getWidth();
        int height= bitmap.getHeight();
        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;
        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHeight);
        return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    }
}
